<template>
  <el-row
    type="flex"
    justify="space-between"
    align="middle"
    style="height: 40px; width: 100%"
  >
    <el-col>
      <!-- 名称应该变成 对应的节点中的name -->
      <strong
        v-if="isRoot"
      ><i class="el-icon-office-building" />{{ treeNode.name }}</strong>
      <span v-else>{{ treeNode.name }}</span>
    </el-col>
    <el-col :span="4">
      <el-row type="flex" justify="end">
        <!-- 两个内容 -->
        <el-col>{{ treeNode.manager }}</el-col>
        <el-col>
          <!-- 下拉菜单 element -->
          <el-dropdown>
            <span> 操作<i class="el-icon-arrow-down" /> </span>
            <!-- 下拉菜单 -->
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item
                @click.native="addSubdepartment"
              >添加子部门</el-dropdown-item>
              <el-dropdown-item
                v-if="!isRoot"
                @click.native="EditorialDepartment"
              >编辑部门</el-dropdown-item>
              <el-dropdown-item
                v-if="!isRoot"
                @click.native="removeSection"
              >删除部门</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
import { delDepartment } from '@/api/department'

export default {
  components: {

  },
  props: {
    treeNode: { // 点击的部门数据
      type: Object,
      required: true
    },
    isRoot: { // 控制不同的地方的使用
      type: Boolean,
      required: true
    }

  },
  data() {
    return {

    }
  },
  computed: {

  },
  watch: {

  },
  created() {

  },
  mounted() {

  },
  methods: {
    async  removeSection() {
      try {
        await delDepartment(this.treeNode.id)
        await this.$confirm('是否确认删除')
        this.$emit('removeSection')
        // Promise.reject(new Error('删除成功'))
      } catch (error) {
        console.log(error)
      }
    },
    addSubdepartment() { // 打开添加部门的模态框
      this.$emit('addSubdepartment', this.treeNode)
    },
    EditorialDepartment() { // 打开编辑的模态框
      this.$emit('EditorialDepartment', this.treeNode)
    }
  }
}
</script>

<style scoped lang="less">
</style>
